import { reactive, toRefs, computed } from "vue";
let componentData = {};
export const initData = (data) => {
  componentData = Object.entries(data).reduce((res, [key, value]) => {
    const reactiveObj = reactive(value);
    const isTitleShow = computed(
      () =>
        (reactiveObj.settingList.switchLs.find((i) => i.type === "title") || {})
          .status
    );
    return { ...res, [key]: { ...toRefs(reactiveObj), isTitleShow } };
  }, {});
};

export const registerMod = (id, data) => {
  const reactiveObj = reactive(data);
  const isTitleShow = computed(
    () =>
      (reactiveObj.settingList.switchLs.find((i) => i.type === "title") || {})
        .status
  );
  componentData[id] = {
    ...toRefs(reactiveObj),
    isTitleShow,
  };
};

export const getData = () => {
  return componentData;
};

export default function useData(id) {
  return componentData[id];
}
